package com.ssc.demo;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CallHello {

    @Autowired
    private UserRemoteClient userRemoteClient;

    @HystrixCommand(fallbackMethod = "reFallBack")
    @GetMapping(value = "/callHello")
    public String calloHello(){
        //此时的调用相当于 http://eureka-user-provide/user/hello
        String result=userRemoteClient.hello();
        System.out.println("调用结果："+result);
        return result;
    }

    public String reFallBack(){
        return "默认失败了";
    }
    @HystrixCommand(fallbackMethod = "reFallBack",commandProperties = {
            @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value = "5000"),
            @HystrixProperty(name="metrics.rollingStats.timeInMilliseconds",value = "100000")
    },threadPoolProperties = {
            @HystrixProperty(name="coreSize",value = "1"),
            @HystrixProperty(name = "maxQueueSize",value="10")
    })
    @GetMapping(value = "/callHello_02")
    public String callHello_02(){
        String result=userRemoteClient.hello();
        System.out.println("调用结果："+result);
        return result;
    }
}
